﻿using System;
using Microsoft.Xna.Framework;

namespace WindowsGame1.Objects3D
{
    public class MatrixMyNameIsNeo
    {
        public double m00;
        public double m01;
        public double m02;
        public double m03;
        public double m10;
        public double m11;
        public double m12;
        public double m13;
        public double m20;
        public double m21;
        public double m22;
        public double m23;
        public double m30;
        public double m31;
        public double m32;
        public double m33;

        public MatrixMyNameIsNeo()
        {
            m00 = 0.0;
            m01 = 0.0;
            m02 = 0.0;
            m03 = 0.0;
            m10 = 0.0;
            m11 = 0.0;
            m12 = 0.0;
            m13 = 0.0;
            m20 = 0.0;
            m21 = 0.0;
            m22 = 0.0;
            m23 = 0.0;
            m30 = 0.0;
            m31 = 0.0;
            m32 = 0.0;
            m33 = 0.0;
        }

        public void setRotate(double ang, double x, double y, double z)
        {

            double c = Math.Cos(ang * 0.0174532);
            double s = Math.Sin(ang * 0.0174532);
            double t = 1.00 - c;

            double fMag = (x * x + y * y + z * z);
            if (fMag == 0) { return; }

            double fMult = 1.0f / Math.Sqrt(fMag);
            x *= fMult;
            y *= fMult;
            z *= fMult;

            m00 = (t * x * x) + c;
            m01 = (t * x * y) + (s * z);
            m02 = (t * x * z) - (s * y);
            m03 = 0;
            m10 = (t * y * x) - (s * z);
            m11 = (t * y * y) + c;
            m12 = (t * y * z) + (s * x);
            m13 = 0;
            m20 = (t * z * x) + (s * y);
            m21 = (t * z * y) - (s * x);
            m22 = (t * z * z) + c;
            m23 = 0;
            m30 = 0;
            m31 = 0;
            m32 = 0;
            m33 = 1;
        }

        public Vector3 transform(Vector3 v)
        {
            Vector3 temp = v;
            v.X = (float)(m00 * temp.X + m01 * temp.Y + m02 * temp.Z + m03);
            v.Y = (float)(m10 * temp.X + m11 * temp.Y + m12 * temp.Z + m13);
            v.Z = (float)(m20 * temp.X + m21 * temp.Y + m22 * temp.Z + m23);

            return v;
        }
    }
}
